package com.gjun.struts.action;

import java.util.List;

import com.gjun.struts.bean.GjunsystemPrivilege;
import com.gjun.struts.resource.GjunPrivilegeResourceIf;
import com.gjun.struts.util.JSONHelper;

public class SaveSystemPrivilegeAction {
    private String result;
    private GjunPrivilegeResourceIf privilegeResourceDAO;
    
    private String label;

	private String href;

	private String info;

	private Integer pid;
	
	private Integer resourcetype;
	
	
	public String getHref() {
		return href;
	}
	public void setHref(String href) {
		this.href = href;
	}
	public String getInfo() {
		return info;
	}
	public void setInfo(String info) {
		this.info = info;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public Integer getPid() {
		return pid;
	}
	public void setPid(Integer pid) {
		this.pid = pid;
	}
	public Integer getResourcetype() {
		return resourcetype;
	}
	public void setResourcetype(Integer resourcetype) {
		this.resourcetype = resourcetype;
	}
	public GjunPrivilegeResourceIf getPrivilegeResourceDAO() {
		return privilegeResourceDAO;
	}
	public void setPrivilegeResourceDAO(GjunPrivilegeResourceIf privilegeResourceDAO) {
		this.privilegeResourceDAO = privilegeResourceDAO;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
    
    
    public String loadAllRootPrivilege(){
    	List<GjunsystemPrivilege> pris = privilegeResourceDAO.loadAllRootPrivilege();
    	try {
			result = JSONHelper.prisToJson(pris);
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	return "success";
    }
    
    public String loadAllLevel2Privilege(){
    	List<GjunsystemPrivilege> pris = privilegeResourceDAO.loadAllPageResourcePrivilege();
    	try {
			result = JSONHelper.prisToJson(pris);
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	return "success";
    }
    
    public String savePrivilege(){
    	
    	GjunsystemPrivilege privilege = new GjunsystemPrivilege();
    	privilege.setHref(href);
    	privilege.setInfo(info);
    	privilege.setLabel(label);
    	privilege.setPid(pid);
    	privilege.setResourcetype(resourcetype);
    	try {
			privilegeResourceDAO.savePrivilege(privilege);
			result = "saveSuccess";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result = "saveFaild";
		}
    	
    	return "success";
    }
}
